#include "painters.h"

QHash<QString, QColor> Painters::color = {
    {"1", QColor("#e3002b")},
    {"2", QColor("#8cc220")},
    {"3", QColor("#fcd600")},
    {"4", QColor("#461d84")},
    {"5", QColor("#944d9a")},
    {"6", QColor("#d40068")},
    {"7", QColor("#ed6f00")},
    {"8", QColor("#0094d8")},
    {"9", QColor("#87caed")},
    {"10", QColor("#c6afd4")},
    {"11", QColor("#871c2b")},
    {"12", QColor("#007a60")},
    {"13", QColor("#e999c0")},
    {"14", QColor("#616020")},
    {"15", QColor("#c8b38e")},
    {"16", QColor("#98d1c0")},
    {"17", QColor("#bb796f")},
    {"18", QColor("#C09453")},
    {"41", QColor("#b5b6b6")},
    {"51", QColor("#cccccc")},
    {"666", QColor("#000000")}
};

std::function<void (QPainter &)> Painters::station(const QStringList &line)
{
    QString tgt_line = (line.empty() || line.size() > 1) ? "666" : line[0];
    if(color.contains(tgt_line) == false) tgt_line = "666";
    return [&](QPainter& painter){
                painter.setRenderHint(QPainter::Antialiasing);
                painter.setPen(QPen(color[tgt_line], 4));
                painter.setBrush(Qt::NoBrush);
    };
}

std::function<void (QPainter &)> Painters::line(const QString &line)
{    
    QString tgt_line = line.isEmpty() ? "666" : line;
    if(color.contains(tgt_line) == false) tgt_line = "666";
    return [&](QPainter& painter){
                painter.setRenderHint(QPainter::Antialiasing);
                painter.setPen(QPen(color[tgt_line], 3));
                painter.setBrush(Qt::NoBrush);
    };
}

std::function<void (QPainter &)> Painters::targetline(bool istarget)
{
    if(istarget){
        return [&](QPainter& painter){
                    painter.setRenderHint(QPainter::Antialiasing);
                    painter.setPen(QPen(Qt::green, 10, Qt::SolidLine));
                    painter.setBrush(Qt::green);
        };
    }
    else {
        return [&](QPainter& painter){
                    painter.setRenderHint(QPainter::Antialiasing);
                    painter.setPen(QPen(Qt::blue, 6, Qt::DashLine));
                    painter.setBrush(Qt::blue);
        };
    }
}
